package com.neusoft.ysu.npms.controller;


import com.github.pagehelper.PageInfo;
import com.neusoft.ysu.npms.pojo.*;
import com.neusoft.ysu.npms.service.IFarmerService;
import com.neusoft.ysu.npms.service.IHelpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 作者：刘金秋
 * @since 2024-06-18
 */
@RestController
@RequestMapping("/farmer")
public class FarmerController {
    @Autowired
    IFarmerService farmerService;

    @RequestMapping("/add")
    public Result add(@RequestBody Farmer farmer) {
//        System.out.println(farmer);
        farmerService.add(farmer);
        return Result.success();
    }
    @RequestMapping("/delete")
    public Result deleteFarmer(@RequestBody Farmer farmer) {
//        System.out.println(farmer);
        farmerService.deleteFarmer(farmer);
        return Result.success();
    }
    @RequestMapping("/update")
    public Result updateFarmer(@RequestBody Farmer farmer){
        farmerService.updateFarmer(farmer);
        return Result.success();
    }

    @RequestMapping("getAll")
    public Result getAll(){
        farmerService.selectAll();
        return Result.success();
    }

    @RequestMapping("findone")
    public Result findone(@RequestBody Farmer farmer){
        //System.out.println(farmer);
        farmerService.findById(farmer);
        return Result.success();
    }

    @RequestMapping("list")
    public Result list(@RequestBody Farmer farmer,
                       @RequestParam(value = "pageNum", required = false, defaultValue = "1") int pageNum,
                       @RequestParam(value = "pageSize", required = false, defaultValue = "5") int pageSize){
        return Result.success(farmerService.getlist(farmer, pageNum, pageSize));
    }
    @RequestMapping("list1")
    public Result list1(@RequestBody FarmerPlus farmerPlus,
                        @RequestParam(value = "pageNum", required = false, defaultValue = "1") int pageNum,
                        @RequestParam(value = "pageSize", required = false, defaultValue = "5") int pageSize){
        return Result.success(farmerService.getlist1(farmerPlus, pageNum, pageSize));
    }

    @RequestMapping("searchByArea")
    public Result searchByArea(@RequestBody Farmer farmer){
        //System.out.println(farmer);
        List<Farmer> famers=  farmerService.searchByArea(farmer);
        System.out.println("111111111111111111111111111111111111111111111111");

        return Result.success(famers);
    }


    @RequestMapping("searchRisk")
    public Result searchRisk(@RequestBody  FarmerRisk farmer){
        List<FarmerRisk> famers=farmerService.searchRisk(farmer);
        System.out.println("前端传来的数据前端传来的数据前端传来的数据前端传来的数据");
        System.out.println("222222222222222222222222222222222222222222222222222");
        System.out.println(farmer);
        System.out.println("前端传来的数据前端传来的数据前端传来的数据前端传来的数据前端传来的数据");
        return Result.success(famers);

    }
}
